package com.jfinal.ext.ueditor.storage;

import com.jfinal.ext.util.MyFileUtil;

import java.io.File;

/**
 * @author Timor
 * @version 1.0
 * @date 2023/03/16 20:47:02
 */
public class StorageResult {
    private final boolean success;
    private String url = null;
    private String relativePath = null;
    private Long length = null;
    private final String message;

    private StorageResult() {
        this.success = true;
        this.message = null;
    }

    private StorageResult(String message) {
        this.success = false;
        this.message = message;
    }


    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    public static StorageResult ok() {
        return new StorageResult();
    }


    public static StorageResult fail() {
        return new StorageResult(null);
    }

    public static StorageResult fail(String message) {
        return new StorageResult(message);
    }


    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    public boolean isOk() {
        return success;
    }

    public boolean isFail() {
        return !success;
    }


    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    public String getFileName() {
        return new File(relativePath).getName();
    }

    public String getFileNameWithoutExtension() {
        return MyFileUtil.getName(new File(relativePath));
    }


    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getRelativePath() {
        return relativePath;
    }

    public void setRelativePath(String relativePath) {
        this.relativePath = relativePath;
    }

    public Long getLength() {
        return length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    public String getMessage() {
        return message;
    }

}
